const shopInfoModel = require("../models/shopInfoModel");
const shopItemModel = require("../models/shopItemModel");
const wordsModel = require("../models/hotWords");

async function getAllShop() {
  const data = await shopInfoModel.find().sort({ _id: -1 });
  return data;
}

async function getOneShop(id) {
  const data = await shopInfoModel.findById(id);
  return data;
}

async function getItemByTab(id, tab = "all") {
  const data = await shopItemModel.find({
    shopId: id,
    tabs: {
      $in: tab,
    },
  });
  console.log(data);
  return data;
}

async function getHotWords() {
  let data = await wordsModel.find().sort({ hotCount: -1 });
  data = data.map((item) => item.word);
  return data;
}

module.exports = { getAllShop, getOneShop, getItemByTab, getHotWords };
